package cn.iocoder.yudao.module.biz.dal.mysql.licence;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.biz.controller.admin.licence.vo.BizLicenceExportReqVO;
import cn.iocoder.yudao.module.biz.controller.admin.licence.vo.BizLicencePageReqVO;
import cn.iocoder.yudao.module.biz.dal.dataobject.licence.BizLicenceDO;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.context.annotation.Lazy;

import java.util.List;

/**
 * 危险作业票主 Mapper
 *
 * @author 芋道源码
 */
@Mapper
@Lazy(value = false)
public interface BizLicenceMapper extends BaseMapperX<BizLicenceDO> {

    default PageResult<BizLicenceDO> selectPage(Long userId,BizLicencePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BizLicenceDO>()
//                .eqIfPresent(BizLicenceDO::getUserId,userId)
                .eqIfPresent(BizLicenceDO::getNumber, reqVO.getNumber())
                .eqIfPresent(BizLicenceDO::getApplicant, reqVO.getApplicant())
                .eqIfPresent(BizLicenceDO::getApplicationUnit, reqVO.getApplicationUnit())
                .eqIfPresent(BizLicenceDO::getGuardian, reqVO.getGuardian())
                .eqIfPresent(BizLicenceDO::getProcessInstanceId, reqVO.getProcessInstanceId())
                .eqIfPresent(BizLicenceDO::getResult, reqVO.getResult())
                .eqIfPresent(BizLicenceDO::getSecurityContent, reqVO.getSecurityContent())
                .eqIfPresent(BizLicenceDO::getLicensor, reqVO.getLicensor())
                .eqIfPresent(BizLicenceDO::getSigner, reqVO.getSigner())
                .eqIfPresent(BizLicenceDO::getSignerSignature, reqVO.getSignerSignature())
                .eqIfPresent(BizLicenceDO::getLicensorSignature, reqVO.getLicensorSignature())
                .eqIfPresent(BizLicenceDO::getInCharge, reqVO.getInCharge())
                .eqIfPresent(BizLicenceDO::getInChargeSignature, reqVO.getInChargeSignature())
                .eqIfPresent(BizLicenceDO::getMainInCharge, reqVO.getMainInCharge())
                .eqIfPresent(BizLicenceDO::getMainInChargeSignature, reqVO.getMainInChargeSignature())
                .eqIfPresent(BizLicenceDO::getLicensorId, reqVO.getLicensorId())
                .eqIfPresent(BizLicenceDO::getSignerId, reqVO.getSignerId())
                .eqIfPresent(BizLicenceDO::getInChargeId, reqVO.getInChargeId())
                .eqIfPresent(BizLicenceDO::getMainInChargeId, reqVO.getMainInChargeId())
                .eqIfPresent(BizLicenceDO::getStatus,reqVO.getStatus())
                .betweenIfPresent(BizLicenceDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .eqIfPresent(BizLicenceDO::getDeptId, reqVO.getDeptId())
                .orderByDesc(BizLicenceDO::getId));
    }

    default List<BizLicenceDO> selectList(BizLicenceExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BizLicenceDO>()
                .eqIfPresent(BizLicenceDO::getNumber, reqVO.getNumber())
                .likeIfPresent(BizLicenceDO::getApplicant, reqVO.getApplicant())
                .eqIfPresent(BizLicenceDO::getApplicationUnit, reqVO.getApplicationUnit())
                .eqIfPresent(BizLicenceDO::getGuardian, reqVO.getGuardian())
                .eqIfPresent(BizLicenceDO::getProcessInstanceId, reqVO.getProcessInstanceId())
                .eqIfPresent(BizLicenceDO::getResult, reqVO.getResult())
                .eqIfPresent(BizLicenceDO::getSecurityContent, reqVO.getSecurityContent())
                .eqIfPresent(BizLicenceDO::getLicensor, reqVO.getLicensor())
                .eqIfPresent(BizLicenceDO::getSigner, reqVO.getSigner())
                .eqIfPresent(BizLicenceDO::getSignerSignature, reqVO.getSignerSignature())
                .eqIfPresent(BizLicenceDO::getLicensorSignature, reqVO.getLicensorSignature())
                .eqIfPresent(BizLicenceDO::getInCharge, reqVO.getInCharge())
                .eqIfPresent(BizLicenceDO::getInChargeSignature, reqVO.getInChargeSignature())
                .eqIfPresent(BizLicenceDO::getMainInCharge, reqVO.getMainInCharge())
                .eqIfPresent(BizLicenceDO::getMainInChargeSignature, reqVO.getMainInChargeSignature())
                .eqIfPresent(BizLicenceDO::getLicensorId, reqVO.getLicensorId())
                .eqIfPresent(BizLicenceDO::getSignerId, reqVO.getSignerId())
                .eqIfPresent(BizLicenceDO::getInChargeId, reqVO.getInChargeId())
                .eqIfPresent(BizLicenceDO::getMainInChargeId, reqVO.getMainInChargeId())
                .eqIfPresent(BizLicenceDO::getStatus,reqVO.getStatus())
                .betweenIfPresent(BizLicenceDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .betweenIfPresent(BizLicenceDO::getCreateTime, reqVO.getStartTime(), reqVO.getEndTime())
//                .eqIfPresent(BizLicenceDO::getDeptId, reqVO.getDeptId())
//                .eqIfPresent(BizLicenceDO::getUserId,reqVO.getUserId())
                .orderByDesc(BizLicenceDO::getId));
    }

    default List<BizLicenceDO> selectListInLicenceIds(List<String> licenceIds){
        return selectList(new LambdaQueryWrapperX<BizLicenceDO>()
                .in(BizLicenceDO::getId,licenceIds));
    }

}
